<!DOCTYPE html>
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>调剂师列表</title>
    <!--{include file='comm/icheck.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>

<div class="container">

        <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                    <span>
                       调剂师编号：<input type="text"  class="form-control input-sm" name="distribution_technician_code" id="distribution_technician_code" style="width:150px;"/>
                    </span>
                    <span>
                       调剂师姓名：<input type="text"  class="form-control input-sm" name="distribution_technician_name" id="distribution_technician_name" style="width:150px;"/>
                    </span>
                    <span>
                       手机号码：<input type="text"  class="form-control input-sm" name="mobile" id="mobile" style="width:150px;"/>
                    </span>
                    <!--
                    <span>
                       配送站：<select class="form-control w150" id="distribution_id" name="distribution_id">
                                    <option value="">请选择</option>
                                    <!--{foreach from=$distribution_array item=distribution}-->
                                    <option value="<!--{$distribution.distribution_id}-->"><!--{$distribution.distribution_name}--></option>
                                    <!--{/foreach}-->
                                </select>
                    </span>
                    -->
                    <span>
                        <button type="button" class="btn btn-primary" id="searchBtn" onclick="distribution.search();">查询</button>
                    </span>
                    <span>
                        <button type="button" class="btn btn-warning" id="clearBtn" onclick="distribution.clearUp();" >重置</button>
                    </span>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


</div>

<div id="pop" style="display: none">
    <div class="panel">

        <div class="panel-body">

            <form id="item_form" onsubmit="return false;" class="form-horizontal">

                <input type="hidden" id="distribution_technician_id" name="distribution_technician_id" value="0">

                <div class="form-group">
                    <label class="col-sm-3 control-label" for="distribution_technician_code">
                        <span class="red">*</span>
                        调剂师编号：
                    </label>
                    <div class="col-sm-9">
                        <input id="save_distribution_technician_code" class="form-control w150" type="text" placeholder="请输入调剂师编号"  name="save_distribution_technician_code">
                    </div>
                </div>


                <div class="form-group" style="display: none">

                    <label class="col-sm-3 control-label">
                        音频文件：
                    </label>

                    <div class="col-sm-9">
                        <input type="button" class="btn btn-default" id="audio_media" value="点击上传音频">
                        <div id="audio_box" style="display: none;margin-top: 5px;"></div>
                        <input type="hidden" name="audio" id="audio" value="" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label" for="distribution_technician_name">
                        <span class="red">*</span>
                        调剂师姓名：
                    </label>
                    <div class="col-sm-9">
                        <input id="save_distribution_technician_name" class="form-control w150" type="text" placeholder="请输入调剂师姓名" name="save_distribution_technician_name" >&nbsp;&nbsp;

                    </div>
                </div>

                <div class="form-group" style="display: none">
                    <label class="col-sm-3 control-label" for="distribution_technician_pwd">
                        调剂师密码：
                    </label>
                    <div class="col-sm-9">
                        <input id="distribution_technician_pwd" class="form-control w150" type="text" placeholder="请输入调剂师密码" name="distribution_technician_pwd" >&nbsp;&nbsp;

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label" for="mobile">
                        <span class="red">*</span>
                        手机号码：
                    </label>
                    <div class="col-sm-9">
                        <input id="save_mobile" class="form-control w150" type="text" placeholder="请输入手机号码" name="save_mobile">
                    </div>
                </div>

                <div class="form-group" style="display: none;">
                    <label class="col-sm-3 control-label" for="distribution_id">
                        <span class="red">*</span>
                        配送站：
                    </label>
                    <div class="col-sm-9">
                        <select class="form-control w150" id="save_distribution_id" name="save_distribution_id">
                            <option value="">请选择</option>
                            <!--{foreach from=$distribution_array item=distribution}-->
                            <option value="<!--{$distribution.distribution_id}-->"><!--{$distribution.distribution_name}--></option>
                            <!--{/foreach}-->
                        </select>
                    </div>
                </div>

            </form>

        </div>

    </div>
</div>

<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/system/distributionTechnician.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 120, align: 'center'},
            {display: "调剂师ID", name : "distribution_technician_id " , width : 80 , sortable : true },
            {display: "调剂师编号", width : 150},
            {display: "调剂师姓名 ", width : 100},
            {display: "手机号码", width : 90 , align:"center"},
            {display: "使用状态", width : 70 , align:"center"}
        ],

        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "distribution.edit.open"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "distribution.del.check"},
            {separator: true},
            {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
            {separator: true},
            {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
        ],
        <!--{/if}-->

        sortname: "distribution_technician_id ",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,

        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    //定义一个调剂师对象
    var distribution = {
        distribution_technician_code:'',
        distribution_technician_name:'',
        mobile:'',

        //查询
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //添加或修改调剂师
        edit: {

            open: function( distribution_technician_id ) {

                if (!distribution_technician_id) {
                    distribution_technician_id = 0;
                }

                E.popup.open({
                    id: 'pop',
                    title: distribution_technician_id == 0 ? '添加调剂师' : '修改调剂师',
                    css: 'width: 600px;',
                    btnName: '保存',
                    btnCall: 'distribution.edit.check();'
                });

                $('.square-checkbox').iCheck({
                    checkboxClass: 'icheckbox_square-blue',
                    radioClass: 'iradio_square-blue',
                    increaseArea: '20%' // optional
                });

                if (distribution_technician_id > 0) {

                    E.ajax_get({
                        url: '/invokingAjax-backend/system/distributionTechnician.ajax?operFlg=2',
                        data: {
                            distribution_technician_id: distribution_technician_id
                        },
                        call: function( o ) {

                            if (o.code == 200) {
                                $('#distribution_technician_id').val(o.data.distribution_technician_id);
                                $('#save_distribution_technician_code').val(o.data.distribution_technician_code);
                                $('#save_distribution_technician_name').val(o.data.distribution_technician_name);
                                $('#save_mobile').val(o.data.mobile);
                                $('#save_distribution_id').val(o.data.distribution_id);
                                $('#distribution_technician_pwd').val(o.data.distribution_technician_pwd);
                                $('#audio').val(o.data.audio);

                                $('#audio_box').html('<audio controls="controls"><source src="' + o.data.audioShow + '" type="audio/ogg" /></audio>').show();

                            }

                        }
                    });

                }

            },

            check: function() {

                this.dt = E.getFormValues('item_form');
                var error_msg = '';

                if (E.isEmpty(this.dt.save_distribution_technician_code))
                    error_msg += '调剂师编号不能为空<br/>';

                if (E.isEmpty(this.dt.save_distribution_technician_name))
                    error_msg += '调剂师姓名不能为空<br/>';

                if (!E.isMobile(this.dt.save_mobile)){
                    error_msg += '手机号码格式不正确<br/>';
                }

                if (error_msg != '') {
                    E.alert(error_msg);
                } else {

                    E.confirm('您确认保存吗？', 'distribution.edit.execute');

                }

            },

            execute: function() {

                E.loadding.open('正在保存，请稍候...');

                E.ajax_post({
                    url: '/invokingAjax-backend/system/distributionTechnician.ajax?operFlg=100&act=edit',
                    data: this.dt,
                    call: 'distribution.edit.result'
                });

            },

            result: function( o ) {

                E.loadding.close();

                if (o.code == 200) {

                    if (this.dt.distribution_technician_id > 0) {
                        E.popup.close();
                    } else {
                        document.getElementById('item_form').reset();
                    }

                    E.alert(o.message, 2, 'distribution.load');
                } else {
                    E.alert(o.message);
                }

            }

        },

        change: {

            check: function( distribution_technician_id, flg ) {

                this.distribution_technician_id = distribution_technician_id;
                this.flg = flg;
                if (flg) {
                    E.confirm('您确认禁用该调剂师吗？', 'distribution.change.execute');
                } else {
                    E.confirm('您确认启用该调剂师吗？', 'distribution.change.execute');
                }

            },

            execute: function() {

                E.ajax_get({
                    url: '/invokingAjax-backend/system/distributionTechnician.ajax?operFlg=100&act=change',
                    data: {
                        distribution_technician_id: this.distribution_technician_id,
                        flg: this.flg
                    },
                    call: 'distribution.change.result'
                });

            },

            result: function( o ) {

                if (o.code == 200) {
                    E.alert(o.message, 2, 'distribution.load');
                } else {
                    E.alert(o.message);
                }

            }

        },

        del: {

            p_array: '',

            check: function() {

                var p_obj = $('#flex').find('tr.trSelected');
                if (p_obj.length == 0) {
                    E.alert('请选择要删除的调剂师');
                } else {

                    var temp_array = new Array();
                    var error_flg = 0;

                    $.each(p_obj, function(k, v) {
                        var id = $(v).attr('id').replace('row', '');

                        temp_array.push($(v).attr('id').replace('row', ''));
                    });


                        this.p_array = temp_array;
                        E.confirm('您确认要删除选中的调剂师吗？', 'distribution.del.execute');


                }

            },

            execute: function() {
                E.loadding.open('正在删除，请稍候...');
                E.ajax_post({
                    url: '/invokingAjax-backend/system/distributionTechnician.ajax?operFlg=100&act=del',
                    data: {
                        p_array: this.p_array
                    },
                    call: 'distribution.del.result'
                });
            },

            result: function( o ) {

                E.loadding.close();
                if (o.code == 200) {
                    E.alert('删除成功', 2, 'distribution.load');
                } else {
                    E.alert(o.message);
                }

            }

        },

        //重置
        clearUp:function(){
            $("#distribution_technician_code").val('');
            $("#distribution_technician_name").val('');
            $("#mobile").val('');
            $("#distribution_id").val('');
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();

        },

        load: function() {
            $("#flex").flexReload();
        }

    };

    //绑定上传音频
    KindEditor.ready(function(K) {
        var kindEditor_upload = K.editor({
            allowFileManager : true,
            uploadJson: '/framework/kindeditor/php/upload_json.php?act=system'
        });
        $(document).on('click', '#audio_media', function() {
            kindEditor_upload.loadPlugin('image', function() {
                kindEditor_upload.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {
                        $('#audio_box').html('<audio controls="controls"><source src="' + url + '" type="audio/ogg" />您的浏览器不支持 audio 标签。</audio>').show();
                        $('#audio_box').hide();
                        $('#audio').val(url);
                        kindEditor_upload.hideDialog();
                    }
                });
            });
        });
    });

</script>

</body>

</html>